package jbrowser.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import jbrowser.JBrowser;

public class Properties extends java.util.Properties {

    private static File configFolder = new File(JBrowser.getHome(), "etc");
    private File configFile;

    public void store() throws IOException {
        store(configFile);
    }

    public void store(File file) throws IOException {
        super.store(new FileOutputStream(file), null);
    }

    public Properties load(String fileName) throws FileNotFoundException, IOException {
        if (!configFolder.exists()) {
            configFolder.mkdir();
        }
        return load(new File(configFolder, fileName));
    }

    public Properties load(File file) throws FileNotFoundException, IOException {
        this.configFile = file;
        super.load(new FileInputStream(file));
        return this;
    }
}
